﻿class Solution {
    public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> ret=new ArrayList<List<Integer>>();
List<Integer> list=new ArrayList<Integer>();
for(int i=0;i<nums.length;i++){
list.add(nums[i]);
}
int n=nums.length;
backtrack(n,list,ret,0);
return ret;
    }
    public void backtrack(int n,List<Integer> list,List<List<Integer>> ret,int first){
        if(first==n){
            ret.add(new ArrayList<Integer>(list));
        
        }
        for(int i=first;i<n;i++){
            Collections.swap(list,first,i);
            backtrack(n,list,ret,first+1);
            Collections.swap(list,first,i);//撤销
        }
    }



}